package com.weu.contorller;

import com.alibaba.fastjson.JSONObject;
import com.weu.bean.Result;
import com.weu.bean.sysUser;
import com.weu.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
    @Autowired
    private UserServiceImpl userServiceImpl;
    //跳转到登录界面
    @RequestMapping("toLogin1")
    public String toLogin(){
        return "login";
    }
    //跳转到注册界面
    @RequestMapping("toRegister")
    public String toRegister(){
        return "registration";
    }
    //注册

    @RequestMapping("register")
    public String register(sysUser user){
        userServiceImpl.register(user);
        return "login";
    }
    //验证用户是否存在
    /*1.验证用户名是否重复*/
    @RequestMapping("/checkName")
    @ResponseBody
    public String checkName(@RequestBody JSONObject jsonParam){
        String name = jsonParam.getString("name");
        sysUser user = userServiceImpl.findUserByName(name);
        if (user==null){
            return "未被注册";
        }else {
            return "该用户名已被注册，请换一个";
        }
    }
}
